package com.itheima_01;
//数据源:C:\Users\wfsxy\Desktop\elementaryclass\day06\视频\17-JLabel展示文本和图片.mp4
//目的地:day11_demo\abc.mp4

import java.io.*;

public class Test02 {
    public static void main(String[] args) throws IOException {
        long statr = System.currentTimeMillis();
        //method1();
        //method2();//耗时:1010毫秒
        //method3();//耗时:耗时:6436毫秒
        method4();//耗时:294毫秒//8192 耗时:222毫秒
        long end =System.currentTimeMillis();
        System.out.println("耗时:"+(end-statr)+"毫秒");

    }

    private static void method4() throws IOException {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day11_demo\\abc.mp4"));
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\wfsxy\\Desktop\\elementaryclass\\day06\\视频\\17-JLabel展示文本和图片.mp4"));
        byte[] bytes = new byte[8192];
        int len ;
        while ((len = bis.read(bytes))!=-1){
            bos.write(bytes);
        }
        bis.close();
        bos.close();
    }

    private static void method3() throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\wfsxy\\Desktop\\elementaryclass\\day06\\视频\\17-JLabel展示文本和图片.mp4"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day11_demo\\abc.mp4"));

        int by;
        while ((by = bis.read())!=-1){
            bos.write(by);
        }
        bis.close();
        bos.close();
    }
    //一个数组读取
    private static void method2() throws IOException {
        FileOutputStream fos = new FileOutputStream("day11_demo\\abc.mp4");
        FileInputStream fis =new FileInputStream("C:\\Users\\wfsxy\\Desktop\\elementaryclass\\day06\\视频\\17-JLabel展示文本和图片.mp4");

        byte[] bytes = new byte[1024];
        int len;
        while ((len=fis.read(bytes))!=-1){
            fos.write(bytes,0,len);
        }
        fis.close();
        fos.close();

    }

    //字节流一个字节复制
    public static void method1() throws IOException {
        //创建基本字节流读
        FileInputStream fis = new FileInputStream("C:\\Users\\wfsxy\\Desktop\\elementaryclass\\day06\\视频\\17-JLabel展示文本和图片.mp4");
        //创建基本字节流写
        FileOutputStream fos = new FileOutputStream("day11_demo\\abc.mp4");


        //读取
        int by ;
        while ((by = fis.read())!=-1){
            fos.write(by);
        }

        //关闭
        fos.close();
        fis.close();
    }
}
